<template>
  <div class="overflow-hidden father">
    <!-- <BasicTable @register="registerTables" /> -->
    <CollapseContainer title="生成校验码" class="nexts">
      <BasicForm
        autoFocusFirstItem
        :labelWidth="100"
        :schemas="schemas"
        :actionColOptions="{ span: 24 }"
        @submit="handleSubmit"
        @reset="handleReset"
      />
    </CollapseContainer>
    <BasicTable @register="registerTable">
      <template #bodyCell="{ column, record }">
        <template v-if="column.dataIndex === 'action' && record.name">
          <TableAction
            class="search"
            @click="$emit('select', record)"
            :actions="[
              {
                icon: 'ant-design:search-outlined',
                tooltip: '查看生成的二维码列表',
              },
            ]"
          />
        </template>
      </template>
    </BasicTable>
  </div>
</template>
<script lang="ts">
  import { defineComponent, ref, ComponentPublicInstance } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { handleFetchParams } from '/@/utils/lamp/common';
  import { RoleEnum } from '/@/enums/roleEnum';
  import { generateTaskCheckCode, getAllCodeYears } from '/@/api/basic/qimo/index';
  import { columns, searchFormSchema } from './defDict.data';
  import { BasicForm, FormSchema } from '../Form/index';
  import { CollapseContainer } from '/@/components/Container';
  import { useUserStore } from '/@/store/modules/user';
  import { useMessage } from '/@/hooks/web/useMessage';
  export default defineComponent({
    // 若需要开启页面缓存，请将此参数跟菜单名保持一致
    name: 'DefDictManagement',
    components: { BasicTable, TableAction, BasicForm, CollapseContainer },
    emits: ['select'],
    setup(_, { emit }) {
      const { t } = useI18n();
      // const userStore = useUserStore();
      // const { createMessage } = useMessage();
      const keyword = ref<string>('');
      // const showSearche: any = userStore.getTenantId;

      // 表格
      const [registerTable, { reload }] = useTable({
        title: '查看校验码',
        api: getAllCodeYears,
        columns: columns(),
        formConfig: {
          name: 'dictSearch',
          labelWidth: 70,
          schemas: searchFormSchema(),
          autoSubmitOnEnter: true,
          resetButtonOptions: {
            preIcon: 'ant-design:rest-outlined',
          },
          submitButtonOptions: {
            preIcon: 'ant-design:search-outlined',
          },
        },
        childrenColumnName: 'typeResultVOList',
        // childrenColumnName: 'typeList',
        isTreeTable: true,
        beforeFetch: handleFetchParams,
        useSearchForm: false,
        showTableSetting: true,
        bordered: true,
        rowKey: 'id',
        rowSelection: {
          type: 'radio',
          columnWidth: 40,
        },
        actionColumn: {
          width: 100,
          title: `查看二维码`,
          dataIndex: 'action',
        },
      });
      const schemas: FormSchema[] = [
        {
          label: '年份',
          field: 'year',
          component: 'Select',
          colProps: { span: 12 },
          componentProps: {
            options: Array.from({ length: 20 }, (_, index) => ({
              label: new Date().getFullYear() + index + '',
              value: new Date().getFullYear() + index,
            })),
          },
        },
        {
          label: '生成数量',
          field: 'count',
          component: 'Input',
          colProps: { span: 12 },
        },
        {
          label: '类型',
          field: 'type',
          component: 'Select',
          colProps: { span: 12 },
          componentProps: {
            options: [
              { value: 'MZ', label: '民主评价', key: '1' },
              { value: 'ZPA', label: '综合评价A', key: '2' },
              { value: 'ZPB', label: '综合评价B', key: '3' },
            ],
          },
        },
      ];
      async function handleSubmit(values: any) {
        const result = await generateTaskCheckCode(values);
        reload();
        return result;
      }
      return {
        t,
        registerTable,
        schemas,
        RoleEnum,
        handleSubmit,
        handleReset: () => {
          keyword.value = '';
        },
      };
    },
  });
</script>
<style>
  .father {
    margin: 20px;
  }

  .nexts {
    margin-bottom: 20px;
  }
</style>
